<template>
  <div class="base" style="width: 100%">
    <div ref="echartsRef" :style="{ width: width, height: hight }"></div>
  </div>
</template>

<script lang="ts">
import { defineComponent, ref, onMounted, watchEffect } from 'vue'
import echart from './hook/echarts'
export default defineComponent({
  props: {
    options: {
      type: Object,
      default: () => {
        return {}
      }
    },
    width: {
      type: String,
      default: '100%'
    },
    hight: {
      type: String,
      default: '500px'
    }
  },
  setup(props) {
    const echartsRef = ref<HTMLElement>()

    onMounted(() => {
      const { setOptions } = echart(echartsRef.value!)
      watchEffect(() => {
        setOptions(props.options)
      })
    })
    return {
      echartsRef
    }
  }
})
</script>

<style scoped></style>
